//
//  ApplyViewController.m
//  CRSCMOA
//
//  Created by 王文晓 on 16/8/8.
//  Copyright © 2016年 王文晓. All rights reserved.
//

#import "ApplyViewController.h"
#import "BaseCollectionViewCell.h"
#import "ApplyTableViewCell.h"
#import "EnterTitleViewController.h"
#import "OfficialDocumentViewController.h"
#import "backView.h"

@interface ApplyViewController ()<UITableViewDelegate,UITableViewDataSource,MyViewDelget>

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, assign) BOOL isApply;   //报销按钮的判断
@property (nonatomic, assign) BOOL isSee;       //报销流程的判断
@property (nonatomic, assign) BOOL isSection;   //分区是否打开的判断
@property (nonatomic, assign) BOOL isRowOpen;   //分区下的单元格是否打开（以下依次类推）
@property (nonatomic, assign) BOOL isRowOpen1;
@property (nonatomic, assign) BOOL isRowOpen2;
@property (nonatomic, assign) BOOL isRowOpen3;
@property (nonatomic, assign) BOOL isRowOpen4;
@property (nonatomic, assign) BOOL isRowOpen5;

//弹窗view

@property (nonatomic, strong) UILabel *AlertLabel;
@property (nonatomic, strong) UITextField *AlertTextField;
@property (nonatomic, strong) UITextField *AlertlineView;
@property (nonatomic, strong) UITextField *AlertConfirmBtn;
@property (nonatomic, strong) UITextField *AlertCancelBtn;
@end

@implementation ApplyViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpNavgationBar];
    
    NSArray *ar = @[@"我发起的",@"我审批的"];
    MyView *myView = [[MyView alloc]initWithArr:ar Bol:YES];
    myView.delget = self;
    
    [self.view addSubview:myView];
    [self.view addSubview:self.tableView];
    
    self.myView = [[MyView alloc]initWithFrame:kRect(0, 0, kScreenWidth, kScreenHeight)];
    self.myView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
    self.myView.hidden = YES;
    [self.view addSubview:self.myView];
<<<<<<< HEAD
=======

>>>>>>> 40d131c2d157ff7092aed1c29e8dd5489e0ace3b
    // Do any additional setup after loading the view.
}

#pragma mark - -----------tableView的代理方法--------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 6;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0) {
        return self.isRowOpen?1:0;
    }else if (section == 1){
        
        return self.isRowOpen1?1:0;
    }else if (section == 2){
        
        return self.isRowOpen2?1:0;
    }else if (section == 3){
        
        return self.isRowOpen3?1:0;
    }else if (section == 4){
        
        return self.isRowOpen4?1:0;
    }else if (section == 5){
        
        return self.isRowOpen5?3:0;
    }else{
        
        return 0;
    }
    
}

//cell赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ApplyTableViewCell *applyCell = [tableView dequeueReusableCellWithIdentifier:@"ApplyCell" forIndexPath:indexPath];
    
    if (indexPath.section == 0) {
        
        applyCell.textLabel.text = @"报销流程（所有人可见）";
        return applyCell;
    }
    
    else if (indexPath.section == 1){
        
        applyCell.textLabel.text = @"请假流程（所有人可见）";
        return applyCell;
    }
    
    else if (indexPath.section == 2){
        
        applyCell.textLabel.text = @"办公流程（所有人可见）";
        return applyCell;
    }
    
    else if (indexPath.section == 3){
        
        applyCell.textLabel.text = @"培训流程（所有人可见）";
        return applyCell;
    }
    
    else if (indexPath.section == 4){
        
        applyCell.textLabel.text = @"出差流程（所有人可见）";
        return applyCell;
    }
    else if (indexPath.section == 5){
        
        if (indexPath.row == 0) {
            
            applyCell.textLabel.text = @"测试会签网关）";
            return applyCell;
        }else if (indexPath.row == 1){
            
            applyCell.textLabel.text = @"测试制定流程）";
            return applyCell;
        }else if (indexPath.row == 2){
            
            applyCell.textLabel.text = @"用车流程（所有人可见）";
            return applyCell;
        }
    }
    
    return nil;
}

//cell点击
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {

            
            //获得xib的UIView--头视图下面的View
            UINib *nib = [UINib nibWithNibName:@"backView" bundle:nil];
             backView *myAlert = [[nib instantiateWithOwner:nil options:nil] firstObject];
<<<<<<< HEAD
             myAlert.frame = kRect(10, kScreenHeight/4, kScreenWidth-20, 200);
             myAlert.backgroundColor = [UIColor whiteColor];
             self.myView.hidden =NO;//灰色view不隐藏
            [self.myView addSubview:myAlert];
 
=======
            myAlert.frame = kRect(10, kScreenHeight/4, kScreenWidth-20, 200);
//            myAlert.center = self.view.center;
            myAlert.backgroundColor = [UIColor whiteColor];
//            myview = myAlert;
            
            self.myView.hidden = NO;
            myAlert.view = self.myView;
            [self.myView addSubview:myAlert];

>>>>>>> 40d131c2d157ff7092aed1c29e8dd5489e0ace3b
           

        }
        
    }
    
    else if (indexPath.section == 1){
        
        
    }
    
    else if (indexPath.section == 2){
        
        
    }
    
    else if (indexPath.section == 3){
        
    }
    
    else if (indexPath.section == 4){
        
        
    }
    else if (indexPath.section == 5){
        
        if (indexPath.row == 0) {
            
            
        }else if (indexPath.row == 1){
            
            
        }else if (indexPath.row == 2){
            
        }
    }
}

//tableHeaderView
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 80)];
    NSArray *array = [NSArray arrayWithObjects:@"报销(1)",@"请假(1)",@"办公(1)",@"培训(1)",@"出差(1)",@"用车(3)", nil];
    
    for (int i = 0; i < section+1; i++) {
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 40)];
        imageView.backgroundColor = [UIColor grayColor];
        [view addSubview:imageView];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 80, 40)];
        label.text = array[section];
        [view addSubview:label];
        
        UIButton *rowBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [rowBtn setFrame:CGRectMake(300, 10, 50, 40)];
        [rowBtn setTitle:@"⌃" forState:UIControlStateNormal];
        [rowBtn addTarget:self action:@selector(sectionBtn:) forControlEvents:UIControlEventTouchUpInside];
        rowBtn.tag = 3000+i;
        [view addSubview:rowBtn];
        
        UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 78, self.view.frame.size.width, 1)];
        lineLabel.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.2];
        [view addSubview:lineLabel];
    }
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 60;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 80;
}

//各个单元格箭头点击回调事件
- (void)sectionBtn:(UIButton *)sender {
    if (sender.tag == 3000) {
        
        self.isRowOpen = !self.isRowOpen;
        [sender setTitle:@"⌄" forState:UIControlStateNormal];
    }if (sender.tag == 3001) {
        
        self.isRowOpen1 = !self.isRowOpen1;
    }if (sender.tag == 3002) {
        
        self.isRowOpen2 = !self.isRowOpen2;
    }if (sender.tag == 3003) {
        
        self.isRowOpen3 = !self.isRowOpen3;
    }if (sender.tag == 3004) {
        
        self.isRowOpen4 = !self.isRowOpen4;
    }if (sender.tag == 3005) {
        
        self.isRowOpen5 = !self.isRowOpen5;
    }
    //    NSLog(@"btn %ld",sender.tag);
    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//自定义SegmentedControl的回调事件
-(void)buttonAction:(id)but{
    UIButton* but1 = but;
    NSLog(@"-- %ld",(long)but1.tag);
    
    if (but1.tag == 1000) {
        
        
    }else if (but1.tag == 1001){
        
    }
    
}

#pragma mark - 设置导航条
- (void)setUpNavgationBar
{
    self.title = @"申请";
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    self.navigationController.navigationBar.translucent = NO;
    UIBarButtonItem *backBtnItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithOriginalName:@"返回按钮.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBtnClick)];
    self.navigationItem.leftBarButtonItem = backBtnItem;
}
- (void)leftBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark --视图懒加载-
- (UITableView *)tableView {
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:kRect(0, 40, kScreenWidth, kScreenHeight-104)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerNib:[UINib nibWithNibName:@"ApplyTableViewCell" bundle:nil] forCellReuseIdentifier:@"ApplyCell"];
    }
    return _tableView;
}

@end
